package com.lagou.work1

import org.apache.flink.streaming.api.scala._

object WordCountScalaStreaming {
  def main(args: Array[String]): Unit = {

    //获取flink 执行环境
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    //获取数据
    val text: DataStream[String] = env.socketTextStream("server1", 9099)
    //对数据进行处理
    val data: DataStream[(String, Int)] = text.flatMap(_.split(" ")).map((_, 1)).keyBy(0).sum(1)
    //输出结果
    data.print()
    env.execute()
  }
}
